package scala.demo

import scala.collection.mutable

object Count {

  val data = List(
    //用户，位置，时间，停留时长
    "UserA,LocationA,8,60",
    "UserA,LocationA,9,60",
    "UserB,LocationB,10,60",
    "UserB,LocationB,11,80"
  )

  val list: List[Map.type] = List(Map)

  def main(args: Array[String]): Unit = {

    var map = Map("a" -> 0)

    map -= ("a")
    for (i <- 0 until data.length) {
      if (map.contains(data(i).split(",")(0)) && map.get(data(i).split(",")(0)).get <= data(i).split(",")(2).toInt) {

        map += (data(i).split(",")(0) -> map.get(data(i).split(",")(0)).get)
      } else {
        map += (data(i).split(",")(0) -> data(i).split(",")(2).toInt)
      }


      if (map.contains(data(i).split(",")(1)) && map.get(data(i).split(",")(1)).get <= data(i).split(",")(3).toInt) {
       var int=map.get(data(i).split(",")(1)).get + data(i).split(",")(3).toInt
        map += (data(i).split(",")(1) -> int)
      } else {
        map += (data(i).split(",")(1) -> data(i).split(",")(3).toInt)
      }


    }

     println(map)
  }
}
